/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dindang.propertyfee.mvp.model.api.service;

import com.dindang.propertyfee.mvp.model.api.PropertyfeeApi;
import com.dindang.propertyfee.mvp.model.entity.BaseResponse;
import com.dindang.propertyfee.mvp.model.entity.Build;
import com.dindang.propertyfee.mvp.model.entity.PropertyCharge;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import retrofit2.Retrofit;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * ================================================
 * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
 * 存放关于用户的一些 API
 * <p>
 * Created by JessYan on 08/05/2016 12:05
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public interface CommonService {
    String HEADER_API_VERSION = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";

    /**
     * 现金收款
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("/paymentBill/cashReceipts.do")
    Observable<BaseResponse<String>> postCash(@Field("ids") String ids,
                                              @Field("userId") String userId,
                                              @Field("userName") String userName,
                                              @Field("paymentName") String paymentName);



    /**
     * 查询近期账单统计
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryRecentCount.do")
    Observable<BaseResponse<PropertyCharge.RecentCount>> queryRecentCount(@Field("corpId") String corpId);

    /**
     * 查询逾期数据
     * @param rows 条数
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryOverdue.do")
    Observable<BaseResponse<List<PropertyCharge.Overdue>>> queryOverdue(@Field("rows") String rows,
                                                                        @Field("corpId") String corpId
    );

    /**
     * 查询近期账单
     *
     * @param startNum 开始区间
     * @param endNum 结束区间
     * @param page 页数
     * @param rows 条数
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryRecentBill.do")
    Observable<BaseResponse<PropertyCharge.RecentBill>> queryRecentBill(@Field("startNum") String startNum,
                                                                        @Field("endNum") String endNum,
                                                                        @Field("page") int page,
                                                                        @Field("rows") int rows,@Field("corpId") String corpId);

    /**
     * 查询近期账单
     * @param page 页数
     * @param rows 条数
     * @param startDate 应收日期开始时间
     * @param endDate 应收日期结束时间
     * @param bid 小区id
     * @param nodeValue 节点值
     * @param corpid 公司id
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryRecentBill.do")
    Observable<BaseResponse<PropertyCharge.RecentBill>> queryRecentBill(@Field("page") int page,
                                                                        @Field("rows") int rows,
                                                                        @Field("startDate") String startDate,
                                                                        @Field("endDate") String endDate,
                                                                        @Field("bid") String bid,
                                                                        @Field("nodeValue") String nodeValue,
                                                                        @Field("corpid") String corpid
    );

    /**
     * 查询近期账单
     * @param page 页数
     * @param rows 条数
     * @param likeValue 模糊搜索
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryRecentBill.do")
    Observable<BaseResponse<PropertyCharge.RecentBill>> queryRecentBill(@Field("page") int page,
                                                                        @Field("rows") int rows,
                                                                        @Field("likeValue") String likeValue,@Field("corpId") String corpId);

    /**
     * 查询权限小区
     * @param corpId 公司id（可不传）
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("building/findBuilding.do")
    Observable<BaseResponse<List<Build.Building>>> findBuilding(@Field("isAdmin") String isAdmin,@Field("cId") String cId,@Field("corpId") String corpId);

    /**
     *
     * @param cCorpid
     * @param cNodecode
     * @param lv
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("buildinginfo/queryNodes.do")
    Observable<BaseResponse<List<Build.Nodes>>> queryNodes(@Field("cCorpid") String cCorpid, @Field("cNodecode") String cNodecode, @Field("lv") String lv, @FieldMap Map<String, String> cNodevaluesMap);

    /**
     * 根据nodedataid查询账单信息
     * @param nodedataId
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("paymentBill/queryByNodedataId.do")
    Observable<BaseResponse<PropertyCharge.NodedataDetail>> queryByNodedataId(@Field("nodedataId") String nodedataId);

    /**
     * 查询收费记录
     * @param page 页数
     * @param rows 条数
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("/paymentBill/queryRecord4Client.do")
    Observable<BaseResponse<List<PropertyCharge.Record4Client>>> queryRecord4Client(@Field("page") int page,
                                                                                    @Field("rows") int rows);

    /**
     * 收款记录详情
     * @param id 确认收款响应的id
     * @return
     */
    @Headers({"Domain-Name: " + PropertyfeeApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("/paymentBill/queryRecordDetail.do")
    Observable<BaseResponse<List<PropertyCharge.RecordDetail>>> queryRecordDetail(@Field("id") String id);
}
